home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / RIBGeneralPolygon.m < prev    next >
Encoding:
Text File  |  1995-03-25  |  3.8 KB  |  185 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5. #import "RIBGeneralPolygon.h"
  6.  
  7. @implementation RIBGeneralPolygon
  8.  
  9. + initialize { return [RIBGeneralPolygon setVersion:1], self; }
  10.  
  11. - (BOOL)hasBoundingBox { return YES; }
  12.  
  13. - init
  14. {
  15.   [super init];
  16.  
  17.   nLoops = 0;
  18.   nVertices = NULL;
  19.   
  20.   return self;
  21. }
  22.  
  23. - setNLoops:(RtInt)newNLoops nVertices:(RtInt *)newNVertices 
  24.      n:(int)newN tokens:(RtToken *)newTokens parms:(RtPointer *)newParms archiveVector:(char **)newArchiveVector
  25.      printfTypeVector:(int *)newPrintfTypeVector printfNVector:(int *)newPrintfNVector
  26. {  
  27.    nLoops = newNLoops;
  28.    nVertices = newNVertices;
  29.    [self setN:newN tokens:newTokens parms:newParms archiveVector:newArchiveVector printfTypeVector:newPrintfTypeVector printfNVector:newPrintfNVector];
  30.  
  31.    dirtyBoundingBox = TRUE;
  32.    return self;
  33. }
  34.  
  35. - free
  36. {
  37.   if (nVertices) { free(nVertices); }
  38.   return [super free];
  39. }
  40.  
  41. // this is used only internally, for setting a copy without freeing the original
  42. - _setNVertices:(RtInt *)newNVertices
  43. {
  44.   int  i;
  45.  
  46.  
  47.   if (newNVertices)
  48.   {  nVertices = (long *)NXZoneMalloc([self zone], nLoops*sizeof(long));
  49.      for (i = 0; i < nLoops; i++) 
  50.      {  nVertices[i] = newNVertices[i];
  51.      }
  52.   }
  53.   else
  54.   {  nVertices = NULL;
  55.   }
  56.   return self;
  57. }
  58.  
  59. - copyFromZone:(NXZone *)zone
  60. {
  61.    id   newCopy = [super copyFromZone:zone];
  62.  
  63.   [newCopy _setNVertices:nVertices];
  64.   return newCopy;
  65. }
  66.  
  67.  
  68.  
  69. - setNLoops:(RtInt)newNLoops { nLoops = newNLoops; dirtyBoundingBox = TRUE; return self; }
  70. - setNVertices:(RtInt *)newNVertices { nVertices = newNVertices; dirtyBoundingBox = TRUE; return self; }
  71.  
  72. - (RtInt)nLoops { return nLoops; }
  73. - (RtInt *)nVertices { return nVertices; }
  74.  
  75. - (BOOL)isMoot
  76. {
  77.   if (!nLoops) { return YES; }
  78.  
  79.   return NO;
  80. }
  81.  
  82. - (BOOL)theSameAs:otherRIBCommand
  83. {
  84.   int    i;
  85.   RtInt  *otherNVertices;
  86.  
  87.  
  88.   if (nLoops != [otherRIBCommand nLoops])
  89.   {  return NO;
  90.   }
  91.   otherNVertices = [otherRIBCommand nVertices];
  92.   for (i = 0; i < nLoops; i++)
  93.   {  if (nVertices[i] != otherNVertices[i])
  94.      {  return NO;
  95.      }
  96.   }
  97.  
  98.   return [super theSameAs:otherRIBCommand];
  99. }
  100.  
  101.  
  102. - (BOOL)similarTo:otherRIBCommand 
  103. {
  104.   int    i;
  105.   RtInt  *otherNVertices;
  106.  
  107.  
  108.   if ([self class] != [otherRIBCommand class])
  109.   {  return NO;
  110.   }
  111.   if (nLoops != [otherRIBCommand nLoops])
  112.   {  return NO;
  113.   }
  114.   otherNVertices = [otherRIBCommand nVertices];
  115.   for (i = 0; i < nLoops; i++)
  116.   {  if (nVertices[i] != otherNVertices[i])
  117.      {  return NO;
  118.      }
  119.   }
  120.  
  121.   return YES;
  122. }
  123.  
  124.  
  125. - renderSelf:(WW3DCamera *)camera  startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
  126. {
  127.   RiGeneralPolygonV(nLoops, nVertices, n, tokens, parms);
  128.   return self;
  129. }
  130.  
  131.  
  132. - (BOOL)isMotionBlurrable { return YES; }
  133.  
  134.  
  135. - (unsigned long int)maxSampleBandwidth {  return ([super maxSampleBandwidth] + (unsigned long int)((1 + nLoops) * sizeof(RtInt))); }
  136.  
  137.  
  138. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  139. {
  140.    int  i;
  141.  
  142.  
  143.    for (i = 0; i < tab; i++)
  144.    {  NXPrintf(stream, "\t");
  145.    }
  146.    NXPrintf(stream, "GeneralPolygon {");
  147.    for (i = 0; i < nLoops; i++)
  148.    {  NXPrintf(stream, "%d ", nVertices[i]);
  149.    }
  150.    NXPrintf(stream, "} ");
  151.    [super writeParameterList:stream];
  152.    return self;
  153. }
  154.  
  155. #define typeVector "i"
  156. #define typeValues &nLoops
  157.  
  158. - read:(NXTypedStream*)stream 
  159. {
  160.     int version;
  161.  
  162.     [super read:stream];
  163.     version = NXTypedStreamClassVersion(stream,"RIBGeneralPolygon");
  164.     if (version == 0) NXReadTypes(stream,"i",&version), version=1;
  165.     if (version == 1) {
  166.     NXReadTypes(stream,typeVector,typeValues);
  167.     nVertices = (long *)NXZoneMalloc([self zone], nLoops*sizeof(long));
  168.     if (nVertices) {
  169.         NXReadArray(stream, "l", nLoops, nVertices);
  170.     }
  171.     } else {
  172.     }
  173.     return self;
  174. }
  175.  
  176. - write:(NXTypedStream*)stream 
  177. {
  178.     [super write:stream];
  179.     NXWriteTypes(stream,typeVector, typeValues);
  180.     NXWriteArray(stream, "l", nLoops, nVertices);
  181.     return self;
  182. }
  183.  
  184. @end
  185.